<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2020/12/9
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.5.0.min.js"></script>
</head>
<body>

<input type="file" name="filename" id="f"/>
<input type="button" value="上传" onclick="upload()"/>
<script>
    function upload() {
        var files=document.getElementById("f").files[0];
        console.log(files);

        var size=files.size;

        console.log(size);


        var formData = new FormData();
        formData.append("filename",files);
        console.log(formData);

        var name=files.name;

        var reg=/\.jpg$/;
        if (!reg.test(name)){
            alert("请上传jpg文件");
            return;
        }
        $.ajax({
            url:"upload",
            data:formData,
            type:"post",
            processData:false,
            contentType:false,
            success:function () {
                alert("提交成功");
            }
        });
    }
</script>
</body>
</html>
